define(["jquery","bbcare"],function($,$bb){
	var servers = {};
	var URL = $bb.baseUrl("followapp");

	/**
	 * 查询用户评估信息
	 */
	servers.ajaxRecordlist = function(params,callback){
		$bb.ajax({
            url: URL + "service/evaluation/recordlist",
            data: JSON.stringify({
                data: {
                	"evaluationType":"DST",
                	"channelType":"2",
                	"queueUserId":params.userId,
                }
            }),
            success: function (data) {
                callback(data,params);
            }
        })
	}

	/**
	 * 获取当前记录id的索引
	 */
	servers.getRecordIndex = function(list,params){
		for (var i = 0; i < list.length; i++) {
			if( list[i].id == params.id ){
				return i;
			}
		}
		return 0;
	}

	/**
	 * 处理info
	 */
	servers.handleInfo = function(info){
		info.sex = info.gender == "F" ? "女" : "男";
		info.age = $bb.simple.formatAge(info.ageDay);
		info.extremely = typeof info.extremely == "string" ? JSON.parse(info.extremely) : info.extremely;
		return info;
	}

	/**
	 * 请求单个评估详情
	 */
	servers.ajaxEvaluationDetail = function(recordId,callback){
		$bb.ajax({
            url: URL + "service/evaluation/getEvaluationDetail",
            data: JSON.stringify({
                data: {
                	"evaluationType":"DST",
                	"channelType":"2",
                	"recordId":recordId,
                }
            }),
            success: function (data) {
                if(data.success){
					callback(data.data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "请求单个评估详情出错！");
				}
            }
        })
	}

	/**
	 * 未完成项处理
	 */
	var unfinished = function(list,name){
		var obj = {};
		if( list && list.length > 0 ){
			obj.name = name + "：";
			obj.content = "";
			for (var i = 0; i < list.length; i++) {
				obj.content += list[i].name + "；";
			}
		}
		return obj;
	}

	/**
	 * 处理info
	 */
	servers.handleRecord = function(data){
		data.extremely = typeof data.extremely == "string" ? JSON.parse(data.extremely) : data.extremely;
		data.unfinished = {
			"intelligence":unfinished(data.extremely.intelligence,"智力"),
			"sociology":unfinished(data.extremely.sociology,"社会交往"),
			"sports":unfinished(data.extremely.sports,"运动"),
		};
		if( data.DQLevel == "正常" &&  data.MILevel == "正常" ){
			data.level = "正常";
		}else if( data.DQLevel == "异常" ||  data.MILevel == "异常" ){
			data.level = "异常";
		}else{
			data.level = "可疑";
		}
		return data;
	}

	/**
	 * 查询评估用户信息
	 */
	servers.ajaxRecordUserlist = function(params,callback){
		$bb.ajax({
            url: URL + "service/evaluation/recordUserlist",
            data: JSON.stringify({
                data: {
                	"evaluationType":"DST",
                	"channelType":"2",
                	"groupBy":"groupByCreateTime",
                	"userId":params.userId
                }
            }),
            success: function (data) {
                if(data.success){
					callback(data);
				}else{
					$bb.toastShow(data.msg ? data.msg : "查询评估用户信息出错！");
				}
            }
        })
	}

	/**
	 * 处理分数
	 */
	var handleScore = function(score){
		if( score == "低于50" ) return 45;
		if( score == "高于150" ) return 155;
		return Number(score);
	}

	/**
	 * 处理图表数据
	 */
	servers.handleCharts = function(list){
		var obj = {};
		obj.arrTime = [];
		obj.arrDq = [];
		obj.arrMi = [];
		if( list && list.length > 0 ){
			for (var i = list.length-1; i >= 0; i--) {
				obj.arrTime.push(list[i].testTime);
				obj.arrDq.push(handleScore(list[i].dqScore));
				obj.arrMi.push(handleScore(list[i].miScore));
			}
		}
		return obj;
	}

	return servers;
});